class SentinelFireProj extends FireProj;

var int RealSpeed;

simulated function PostNetBeginPlay()
{
	Velocity = RealSpeed * Vector(Rotation);
	Acceleration = Velocity / 1.5;
}

function Timer()
{
	local Pawn P;
	local Cooker Inv;

	//Flames expand with time.
	SetCollisionSize(CollisionRadius + 2.5, CollisionHeight + 2.5);

	//Simple damage radius.
	if(Role == ROLE_Authority)
	{
		//Damage reduces with distance.
		Damage = Max(Default.Damage * Sqrt(Default.CollisionHeight / CollisionHeight), 1);
		HurtRadius(Damage, CollisionRadius * 5, MyDamageType, MomentumTransfer, Location);
	}

	//Setting people on fire is handled here.
	if(Role == ROLE_Authority && bDoTouch)
	{
		foreach TouchingActors(class'Pawn', P)
		{
			if(P.Health > 0 && (!Level.Game.bTeamGame || !P.Controller.SameTeamAs(InstigatorController)))
			{
				P.CreateInventory("Taskforces.Cooker");
				Inv = Cooker(P.FindInventoryType(class'Taskforces.Cooker'));

				if(Inv != None)
				{
					Inv.DamageType = BurnDamageType;
					Inv.Chef = Instigator;
					Inv.DamageDealt = 0;
					Inv.Temperature += 0.6;
					Inv.WaitTime = 0;
				}
			}
		}
	}

	bDoTouch = !bDoTouch;
}

//Sentinels don't damage their owner or themselves.
simulated function HurtRadius( float DamageAmount, float DamageRadius, class<DamageType> DamageType, float Momentum, vector HitLocation )
{
	local actor Victims;
	local float damageScale, dist;
	local vector dir;

	if( bHurtEntry )
		return;

	bHurtEntry = true;
	foreach VisibleCollidingActors( class 'Actor', Victims, DamageRadius, HitLocation )
	{
		// don't let blast damage affect fluid - VisibleCollisingActors doesn't really work for them - jag
		if(Victims != self && Victims.Role == ROLE_Authority && !Victims.IsA('FluidSurfaceInfo') && Victims != Owner)
		{
			dir = Victims.Location - HitLocation;
			dist = FMax(1,VSize(dir));
			dir = dir/dist;
            //TODO WTF IS THIS FOR!!?!>!
			if(Instigator == None || Instigator.Controller == None)
				Victims.SetDelayedDamageInstigatorController(InstigatorController);

			if((Victims.IsA('ShieldSphere') && ShieldSphere(Victims).Shield.Sentinel == sentinel(owner)) || (Victims.IsA('BigShieldSphere') && BigShieldSphere(Victims).Shield.myteam == sentinel(owner).myteam))
				damageScale = 0;
			else
			    damageScale = 1 - FMax(0,(dist - Victims.CollisionRadius)/DamageRadius);

			Victims.TakeDamage
			(
				damageScale * DamageAmount,
				Instigator,
				Victims.Location - 0.5 * (Victims.CollisionHeight + Victims.CollisionRadius) * dir,
				(damageScale * Momentum * dir),
				DamageType
			);

			if (Vehicle(Victims) != None && Vehicle(Victims).Health > 0)
				Vehicle(Victims).DriverRadiusDamage(DamageAmount, DamageRadius, InstigatorController, DamageType, Momentum, HitLocation);
		}
	}

	bHurtEntry = false;
}

defaultproperties
{
     RealSpeed=500
     BurnDamageType=Class'taskforces.DamTypeSentinelBurn'
     Speed=1000.000000
     MyDamageType=Class'taskforces.DamTypeSentinelFlame'
}
